home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / share / pyshared / ibus / common.py < prev    next >
Encoding:
Python Source  |  2009-11-05  |  5.1 KB  |  164 lines

  1. # vim:set et sts=4 sw=4:
  2. #
  3. # ibus - The Input Bus
  4. #
  5. # Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
  6. #
  7. # This library is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU Lesser General Public
  9. # License as published by the Free Software Foundation; either
  10. # version 2 of the License, or (at your option) any later version.
  11. #
  12. # This library is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. # GNU Lesser General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Lesser General Public
  18. # License along with this program; if not, write to the
  19. # Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  20. # Boston, MA  02111-1307  USA
  21.  
  22. __all__ = (
  23.         "IBUS_IFACE_IBUS",
  24.         "IBUS_SERVICE_IBUS",
  25.         "IBUS_PATH_IBUS",
  26.         "IBUS_IFACE_CONFIG",
  27.         "IBUS_IFACE_PANEL",
  28.         "IBUS_IFACE_ENGINE",
  29.         "IBUS_IFACE_ENGINE_FACTORY",
  30.         "IBUS_IFACE_INPUT_CONTEXT",
  31.         "IBUS_IFACE_NOTIFICATIONS",
  32.         "default_reply_handler",
  33.         "default_error_handler",
  34.         "DEFAULT_ASYNC_HANDLERS",
  35.         "CONFIG_GENERAL_SHORTCUT_TRIGGER",
  36.         "CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE",
  37.         "CONFIG_GENERAL_SHORTCUT_PREV_ENGINE",
  38.         "CONFIG_GENERAL_SHORTCUT_TRIGGER_DEFAULT",
  39.         "CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE_DEFAULT",
  40.         "CONFIG_GENERAL_SHORTCUT_PREV_ENGINE_DEFAULT",
  41.         "main",
  42.         "main_quit",
  43.         "main_iteration",
  44.         "get_address",
  45.         "get_socket_path"
  46.     )
  47.  
  48. import os
  49. import sys
  50. from xdg import BaseDirectory
  51. import ctypes
  52.  
  53. # __display = os.environ["DISPLAY"]
  54. # __hostname, __display_screen = __display.split(":", 1)
  55. # if not __hostname.strip():
  56. #     __hostname = "unix"
  57. # __display_number = __display_screen.split(".")[0]
  58. # __username = None
  59. # try:
  60. #     __username = os.getlogin()
  61. # except:
  62. #     pass
  63. # if not __username:
  64. #     __username = os.getenv ("LOGNAME")
  65. # if not __username:
  66. #     __username = os.getenv ("USER")
  67. # if not __username:
  68. #     __username = os.getenv ("LNAME")
  69. # if not __username:
  70. #     __username = os.getenv ("USERNAME")
  71. # libibus = ctypes.CDLL("libibus.so")
  72. # id = ctypes.c_char_p(libibus.ibus_get_local_machine_id()).value
  73. # IBUS_SOCKET_FILE = os.path.join(BaseDirectory.xdg_config_home,
  74. #                                 "ibus", "bus",
  75. #                                 "%s-%s-%s"% (id, __hostname, __display_number))
  76. # def get_address():
  77. #     libibus = ctypes.CDLL("libibus.so")
  78. #     address = ctypes.c_char_p(libibus.ibus_get_address()).value
  79. #     return address
  80. #     address = os.getenv("IBUS_ADDRESS")
  81. #     if address:
  82. #         return address
  83. #     try:
  84. #         for l in file(IBUS_SOCKET_FILE):
  85. #             if not l.startswith("IBUS_ADDRESS="):
  86. #                 continue
  87. #             address = l[13:]
  88. #             address = address.strip()
  89. #             break
  90. #     except:
  91. #         return None
  92. #     return address
  93.  
  94. libibus = ctypes.CDLL("libibus.so.1")
  95. get_address = libibus.ibus_get_address
  96. get_address.restype=ctypes.c_char_p
  97.  
  98. get_socket_path = libibus.ibus_get_socket_path
  99. get_socket_path.restype=ctypes.c_char_p
  100.  
  101. # __session_id = os.getenv ("IBUS_SESSION_ID")
  102. # IBUS_ADDR = "unix:path=/tmp/ibus-%s%s/ibus-%s-%s" % (__username,
  103. #                                                      "-" + __session_id if __session_id else "",
  104. #                                                      __hostname,
  105. #                                                      __display_number)
  106. # IBUS_ADDR  = "tcp:host=localhost,port=7799"
  107.  
  108. IBUS_IFACE_IBUS     = "org.freedesktop.IBus"
  109. IBUS_PATH_IBUS      = "/org/freedesktop/IBus"
  110. IBUS_SERVICE_IBUS   = "org.freedesktop.IBus"
  111.  
  112. IBUS_IFACE_PANEL            = "org.freedesktop.IBus.Panel"
  113. IBUS_IFACE_CONFIG           = "org.freedesktop.IBus.Config"
  114. IBUS_IFACE_ENGINE           = "org.freedesktop.IBus.Engine"
  115. IBUS_IFACE_ENGINE_FACTORY   = "org.freedesktop.IBus.EngineFactory"
  116. IBUS_IFACE_INPUT_CONTEXT    = "org.freedesktop.IBus.InputContext"
  117. IBUS_IFACE_NOTIFICATIONS    = "org.freedesktop.IBus.Notifications"
  118.  
  119. def default_reply_handler( *args):
  120.     pass
  121.  
  122. def default_error_handler(e):
  123.     print >> sys.stderr, e
  124.  
  125. DEFAULT_ASYNC_HANDLERS = {
  126.     "reply_handler" : default_reply_handler,
  127.     "error_handler" : default_error_handler
  128. }
  129.  
  130. CONFIG_GENERAL_SHORTCUT_TRIGGER     = "/general/keyboard_shortcut_trigger"
  131. CONFIG_GENERAL_SHORTCUT_TRIGGER_DEFAULT = [
  132.     "Ctrl+space",
  133.     "Zenkaku_Hankaku",
  134.     "Hangul"]
  135. CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE = "/general/keyboard_shortcut_next_engine"
  136. CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE_DEFAULT = []
  137. CONFIG_GENERAL_SHORTCUT_PREV_ENGINE = "/general/keyboard_shortcut_prev_engine"
  138. CONFIG_GENERAL_SHORTCUT_PREV_ENGINE_DEFAULT = []
  139.  
  140. __mainloop = None
  141.  
  142. def __init_main_loop():
  143.     global __mainloop
  144.     if __mainloop == None:
  145.         import gobject
  146.         __mainloop = gobject.MainLoop()
  147.  
  148. def main():
  149.     __init_main_loop()
  150.     __mainloop.run()
  151.  
  152. def main_quit():
  153.     global __mainloop
  154.     if __mainloop:
  155.         __mainloop.quit()
  156.     
  157. def main_iteration(may_block=False):
  158.     __init_main_loop()
  159.     return __mainloop.get_context().iteration(may_block)
  160.